package priv.yiyuan.example.design.chain;

/**
 * 租户信息获取
 *
 * @author YiYuan
 * @data 2025/10/11
 * @apoNote
 */
public class TenantInfoCommand extends AbstractLoginCommand {

    @Override
    protected boolean process(LoginContext context) {
        if (context.isAccountValid()) {
            context.setErrorMessage("账号未校验通过。");
            return false;
        }

        System.out.println("正在根据包名获取租户信息: " + context.getAppPackageName());

        String packageName = context.getAppPackageName();
        if (packageName.equals("com.app.enterprise")) {
            context.setTenantId("T001");
            context.setTenantName("企业版租户");
            System.out.println("√ 租户信息获取成功: T001 - 企业版租户。");
            return true;
        }
        else if (packageName.equals("com.app.basic")) {
            context.setTenantId("T002");
            context.setTenantName("基础版租户");
            System.out.println("√ 租户信息获取成功: T002 - 基础版租户。");
            return true;
        }
        else {
            context.setErrorMessage("APP包名无效或未注册租户。");
            return false;
        }
    }

}
